<template>
  <el-backtop :right="100" :bottom="100" />
<Header></Header>
  <div class="wp-title_content" style="word-wrap: break-word; padding: 0px; border-color: transparent; border-width: 0px; height: 48px; width: 134px; display: block;margin-top: 20px;margin-left: 10%">
    <!--    购买订购样式-->
    <div class="circle" style="float: left">FS</div>
    <p>
      <span style="color: rgb(242, 89, 75); font-family: Microsoft YaHei; font-size: 20px; line-height: 140%;">鲜花分类</span>
    </p>
    <p>
        <span style="color: rgb(102, 102, 102); font-family: Microsoft YaHei; font-size: 10px; letter-spacing: 0px; line-height: 140%;">
        FLOWER SHOPPING
        </span><br></p>
  </div>
<div style="display: flex;width: 85%; height: 100%; margin: 30px auto;  ">
  <div style="flex: 0.2;" >
    <sidebar @click="si" :categories="data.categories"></sidebar>
  </div>
  <div style=" flex: 1;margin-left: 30px;" >
    <div>
      <!-- 根据 product 显示不同的内容 -->
        <div class="s_spring"  >
          <div  v-for="item in data.seasonsData" style="overflow: hidden;" :key="item.imageUrl" class="product-item">
            <a  :href="'/product/' + item.flowerId">
            <div class="img-wrapper">
              <img :src="item.imageUrl" alt="商品图片">
            </div>
            <div class="info-wrapper">
              <p class="name">{{ item.flowerName }}</p>
              <p class="name" style="color: #a87567;font-size: 12px">{{ item.groupName }}</p>
              <p class="price">价格：￥{{ item.price }}</p>
              <p class="description" >{{ item.description }}</p>
              <div class="button-container">
                <el-button color="#7a80ee" :dark="isDark" plain @click="addToCart(item)">
                  <ShoppingCart />
                  购买
                </el-button>
              </div>
            </div>
            </a>
          </div>
        </div>
      </div>
    </div>
  </div>

</template>

<script setup>
// 图标
import {ShoppingCart, ShoppingTrolley} from '@element-plus/icons-vue'
import {ref, watch, computed, reactive} from 'vue';
import Header from "@/components/Header.vue";
import Sidebar from "@/components/Sidebar.vue";
import { useRoute } from 'vue-router';
import request from "@/utils/request";

const route = useRoute();
// 我没搞懂下面这行代码有什么用，删了好像也能用

const data=reactive({
  categories:[],
  seasonsData:[],
  aa:route.query.product,
})


// 直接声明 product，无需 return
const product = ref(decodeURIComponent(route.query.product || ''));
// console.log(product)

// console.log(route.query.product)


request.get("/flower/page/group",{
  params:{
    groupId:data.aa
  }
}).then(res => {
  data.seasonsData = res.data
  console.log(data.seasonsData)
})


request.get("/group/page").then(res => {
  data.categories = res.data.records
})

console.log(data.aa)
const si=()=>{
  window.location.reload();
}

watch(() => route.query.product, (newProduct) => {
  product.value = decodeURIComponent(newProduct || '');
  // console.log(product.value)
});

const addToCart = (product) => {
  console.log('添加到购物车:', product);
};
</script>


<style scoped>
.example-pagination-block + .example-pagination-block {
  margin-top: 10px;
}
.example-pagination-block .example-demonstration {
  margin-bottom: 16px;
}
.el-link:hover{
  background-color: #f8e1d9;
  color: #0e0c0c;
}

.s_spring {  /* 内容样式 */
  display: flex;
  flex-wrap: wrap; /* 允许换行 */
  margin: 0 auto;
  max-width: 1200px;
}

.product-item {
  width: 30%;
  height: 297px;
  margin-bottom: 20px;
  margin-right: 20px;
  box-sizing: border-box; /* 包括边框和内边距在内计算宽度 */
  padding: 10px;
  border: 2px solid #eeeeee;
  position: relative;
}

.img-wrapper {
  width: 100%;
  height: 150px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  margin-top: 15px;
  margin-bottom: 30px;
}

.img-wrapper img {
  width: 150px;
  max-width: 100%;
  max-height: 100%;
  object-fit: cover;
  border-radius: 5px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.info-wrapper {
  margin-top: 10px;
}
.name{
  font-weight: bold;
  color: #0e0c0c;
}
.name, .price, .description {
  margin: 5px 10px;
  font-size: 14px;
}

.price {
  color: #f2594b;
  font-size: 13px;
}

.description {
  font-size: 14px;
  color: #bebebe;
  width: 100%;
}
.button-container {
  position: absolute;
  bottom: 26px;
  right: 20px;

}

a{
  text-decoration: none;
}
.product-item:hover {
  border-color: #f2594b;
}
.circle {
  margin-top: 10px;
  margin-right: 5px;
  width: 30px;
  height: 30px;
  background-color: #ff6347;
  border-radius: 50%;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  line-height: 180%;
  color: #FFFFFF;
  text-align: center;
}
</style>
